package com.pioneer.app.sms.mobile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Properties;

import config.SMSConfig;

public class SMSWebService {

	private static String SMS_SERVICE_URL="sms.service.url";
	private static String SMS_SYS_CODE="sms.sys.code";
	private static String SMS_EXTENDNUMBER="sms.extendnumber";
	private Properties prs=new Properties();
	
	public SMSWebService()
	
	{
		InputStream in=this.getClass().getResourceAsStream("smsservice.properties");
		
		try {
			prs.load(in);
			
		} catch (IOException e) {
			System.out.println("读取配置文件出错！");
			e.printStackTrace();
		}
	}
	public  void sendSMS(String content, String mobilePhones, String priority,String messageFlag, String moduleName, String exNumber)throws Exception
	{
		String strURL = this.prs.getProperty(SMS_SERVICE_URL);
		//System.out.println(""+strURL);
		String response = "";
		boolean success = false;
        try {
    		strURL += "?MobilePhones=" + mobilePhones
			+ "&Content=" + content
			+ "&Priority=" + priority 
			+ "&ExNumber=" + exNumber 
			+ "&MessageFlag=" + messageFlag 
			+ "&ModuleName=" + moduleName;
            URL objURL = new URL(strURL);
            URLConnection objConn = objURL.openConnection();
            objConn.setDoInput(true);
            BufferedReader br = new BufferedReader(new InputStreamReader(
                    objConn.getInputStream()));
            String line = br.readLine();
            while (line != null) {
                response += line;
                line = br.readLine();
            }
            br.close();
            success = true;
        } catch (Exception e) {
        	throw e;
        }

	}
}
